<?php

if (!defined('BASE_DIR')) exit;

if (defined('ACP'))
{
	$modul['ModulName'] = 'Магазин';
	$modul['ModulPfad'] = 'shop';
	$modul['ModulVersion'] = '1.4';
	$modul['Beschreibung'] = 'Магазин';
	$modul['Autor'] = "Edit New";
	$modul['MCopyright'] = "&copy; 2012 ";
	$modul['Status'] = 1;
	$modul['IstFunktion'] = 0;
	$modul['ModulTemplate'] = 1;
	$modul['AdminEdit'] = 1;
	$modul['ModulFunktion'] = null;
	$modul['CpEngineTagTpl'] = 'index.php?module=shop';
	$modul['CpEngineTag'] = null;
	$modul['CpPHPTag'] = null;
}

	global $AVE_Template;

	if (defined('SSLMODE') && SSLMODE == 1 && $_SERVER['SERVER_PORT'] == '80') header('Location:'.get_redirect_link());
	if (defined('SSLMODE') && SSLMODE != 1 && $_SERVER['SERVER_PORT'] == '443') header('Location:'.get_redirect_link());

	//=======================================================
	// Klasse einbinden
	//=======================================================
	if (defined('ACP') && !(isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete'))
	{
		require_once(BASE_DIR . '/modules/shop/class.shop_admin.php');
	}
	else
	{
		require_once(BASE_DIR . '/modules/shop/class.shop.php');
	}
	require_once(BASE_DIR . '/functions/func.modulglobals.php');
	require_once(BASE_DIR . '/modules/shop/funcs/func.parent_categ.php');
	require_once(BASE_DIR . '/modules/shop/funcs/func.rewrite.php');
	include_once(BASE_DIR . '/modules/shop/class.107.php');
	include_once(BASE_DIR . '/modules/shop/class.receipt.php');
	
	
	function cpShopNavi()
	{
		set_modul_globals('shop');
		$shop = new Shop;
		echo $shop->fetchShopNavi();
	}
	
	function Show_StartCategs()
	{
		set_modul_globals('shop');
		$shop = new Shop;
		echo $shop->StartCategs();
	}
		
	function BasketItems()
	{
		set_modul_globals('shop');
		$shop = new Shop;
		return $shop->_showBasketItems();
	}	
	
	function PrintResultPage($transaction_result)
	{
		set_modul_globals('shop');
		$shop = new Shop;
		$shop->checkShop();
		$shop->getTplSettings();
		$shop->PrintResultPage($transaction_result);
	}
	
	function topseller($lim='', $cat='', $scroll='')
	{
		$lim = (int)$lim;
		$cat = (int)$cat;
		$scroll = (int)$scroll;
		set_modul_globals('shop');
		$shop = new Shop;
		echo $shop->_topSeller($lim, $cat, $scroll);
	}	
	
//if ((isset($_REQUEST['module']) && $_REQUEST['module'] == 'shop'  && UGROUP != '2') || (isset($_REQUEST['mod']) && $_REQUEST['mod'] == 'shop'))
if ((isset($_REQUEST['module']) && $_REQUEST['module'] == 'shop') || (isset($_REQUEST['mod']) && $_REQUEST['mod'] == 'shop'))
{


	if (defined('THEME_FOLDER')) $AVE_Template->assign('shop_images', 'templates/' . THEME_FOLDER . '/modules/shop/');


	if (defined('THEME_FOLDER')) $AVE_Template->assign('theme_folder', THEME_FOLDER);

	$_REQUEST['action'] = empty($_REQUEST['action']) ? 'shopstart' : $_REQUEST['action'];

	if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'shop')
	{
		require_once(BASE_DIR . '/functions/func.modulglobals.php');
		set_modul_globals('shop');
		$shop = new Shop;
		

		switch ($_REQUEST['action'])
		{
			case 'shopstart':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->displayShopStart();
				break;

			case 'product_detail':
				if (!isset($_REQUEST['product_id']) || !is_numeric($_REQUEST['product_id']))
				{
					header('Location:index.php?module=shop');
					exit;
				}
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->showDetails((int)$_REQUEST['product_id']);
				break;

			case 'addtobasket':
				$shop->checkShop();
				$shop->addtoBasket($_REQUEST['product_id']);
				break;	

			case 'sendcouponcode':
				$shop->checkShop();
				$shop->sendcouponcode($_REQUEST['couponcode']);
				break;	

			case 'addtobasket2':
				$shop->checkShop();
				//$shop->addtoBasket2($_REQUEST['product_id']);
				$shop->addtoBasket2();
			break;
			

			case 'addtowishlist':
				$shop->checkShop();
				$shop->addtoWishlist($_REQUEST['product_id']);
				break;


			case 'deltowishlist':
				$shop->checkShop();
				$shop->deltowishlist($_REQUEST['product_id']);
				break;


			case 'wishlist':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->myWishlist();
				break;				
				
				
				
			case 'delitem':
				$shop->delItem($_REQUEST['product_id']);
				break;

			case 'showbasket':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->showBasket();
				break;

			case 'checkout':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->checkOut();
				break;

			case 'checkoutinfo':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->checkOutInfo();
				break;

			case 'PaymentInfo':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->PaymentInfo($_REQUEST['theme_folder'], $_REQUEST['payid']);
				break;

			case 'myorders':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->myOrders();
				break;

			case 'mydownloads':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->myDownloads();
				break;

			case 'infopage':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->getInfoPage();
				break;
			
				
			case 'order_request':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->order_request($_REQUEST['order']);
			break;			
			
			case 'order_request_false':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->order_request_false($_REQUEST['order']);
			break;				
				
				
			case 'payment':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->payment(strip_tags($_REQUEST['transaction_result']));
				break;			
				
			case 'resultpayment':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->PrintResultPage(strip_tags($_REQUEST['result']));
				break;
				
			case 'result_qiwi':
				$shop->checkShop();
				$shop->getTplSettings();
				$shop->resultqiwi(strip_tags($_SESSION['result_qiwi']), strip_tags($_SESSION['result_qiwi_o']), strip_tags($_SESSION['result_qiwi_s']), strip_tags($_SESSION['result_qiwi_p']));
				break;
				
			case 'getPodVariants':
				$shop->_getPodVariants($_REQUEST['varId'], $_REQUEST['val'], $_REQUEST['products']);
				break;
				
			case 'check_bill':
				$shop->check_data_billing();
				break;
				
				
				
			case 'get_search':
				$shop->formDynamic((int)$_REQUEST['KatId']);
			break;				
				

			
			case 'get_num':
				$shop->GetNum();
			break;	
			
			case 'seller':
				$shop->_topSeller(10, '', 'seller');
			break;	
			
			case 'newitem':
				$shop->_topSeller(10, '', 'newitem');
			break;	
			
			case 'descount':
				$shop->_topSeller(10, '', 'descount');
			break;	
			
			case 'leaders':
				$shop->_topSeller(10, '', 'leaders');
			break;				
			
				
				
				
				
				
				
				
				
				
				
				
		}
	}

	//=======================================================
	// Admin - Aktionen
	//=======================================================
	if (defined('ACP') && !empty($_REQUEST['moduleaction']))
	{
		require_once(BASE_DIR . '/modules/shop/sql.php');

		$tpl_dir = BASE_DIR . '/modules/shop/templates_admin/';
		$tpl_dir_source = BASE_DIR . '/modules/shop/templates_admin';
		$lang_file = BASE_DIR . '/modules/shop/lang/' . $_SESSION['admin_language'] . '.txt';

		$AVE_Template->config_load($lang_file, 'admin');
		$config_vars = $AVE_Template->get_config_vars();
		$AVE_Template->assign('config_vars', $config_vars);
		$AVE_Template->assign('source', $tpl_dir_source);

		$receipt = new receipt;
		$shop = new Shop;
		$RussianpostLabel107 = new RussianpostLabel107;
		global $AVE_DB;
		
		$AVE_Template->caching = true;            // Включаем кеширование
		$AVE_Template->cache_lifetime = 60*60*24; // Время жизни кеша 1 день в секундах
		$AVE_Template->cache_dir .= '/shop';   // Папка для кеша модуля


		$_SESSION['use_editor'] = get_settings('use_editor');

		// Проверяем, есть ли папка для кеша, если нет (первый раз) — создаем
		if (!is_dir($AVE_Template->cache_dir))
		{
			$oldumask = umask(0);
			@mkdir($AVE_Template->cache_dir, 0777);
			umask($oldumask);
		}
				
		switch ($_REQUEST['moduleaction'])
		{
			case '1':
				$shop->shopStart($tpl_dir);
				break;
// edit

case 'variant_category':
	$shop->variantsCategories($tpl_dir);
break;

case 'products':
	$shop->displayProducts($tpl_dir);
break;

case 'edit_product':
	$shop->editProduct($tpl_dir);
break;
	
case 'edit_template':
	$shop->edit_template($tpl_dir);
break;

case 'product_categs':
	$shop->productCategs($tpl_dir);
break;

case 'delcateg':
	$shop->delCategCall($_REQUEST['Id']);
break;

case 'edit_categ':
	$shop->editCateg($tpl_dir, $_REQUEST['Id']);
break;
				
				
				
				
				
				
				


			case 'settings':
				$shop->Settings($tpl_dir);
				break;

			case 'email_settings':
				$shop->emailSettings($tpl_dir);
				break;

			case 'shipping':
				$shop->shopShipper($tpl_dir);
				break;


			case 'edit_comments':
				$shop->editComments($tpl_dir);
				break;

			case 'editshipper':
				$shop->editShipper($tpl_dir);
				break;

			case 'editshipper_cost':
				$shop->editshipperCost($tpl_dir);
				break;

			case 'paymentmethods':
				$shop->paymentMethods($tpl_dir);
				break;

			case 'editpaymentmethod':
				$shop->editPaymentMethod($tpl_dir, $_REQUEST['Id']);
				break;

			case 'deletemethod':
				$shop->deleteMethod($_REQUEST['MId']);
				break;

			case 'timeshipping':
				$shop->shipperTime($tpl_dir);
				break;

			case 'timeshippingnew':
				$shop->shipperTimeNew();
				break;

			case 'newmethod':
				$shop->newPaymentMethod();
				break;



			case 'edit_variants_category':
				$shop->editVariantsCategory($tpl_dir, $_REQUEST['Id']);
				break;

//			case 'new_variants_category':
//				$shop->newVariantsCategories();
//				break;

//			case 'delete_variants_category':
//				$shop->deleteVariantsCategory($_REQUEST['Id']);
//				break;



/*
			case 'product_new':
				$shop->newProduct($tpl_dir);
				break;
*/


			
		 	case 'translit':
				$shop->translit($_REQUEST['title'], 'echo');
			break;			
				
			case 'product_vars':
				$shop->prouctVars($tpl_dir, $_REQUEST['Id'], $_REQUEST['KatId'], $_REQUEST['KatId_Multi']);
				break;

			case 'units':
				$shop->Units($tpl_dir);
				break;

			case 'units_new':
				$shop->UnitsNew();
				break;

			case 'manufacturer':
				$shop->Manufacturer($tpl_dir);
				break;

			case 'manufacturer_new':
				$shop->ManufacturerNew();
				break;

			case 'usergroup':
				$shop->usergroup($tpl_dir);
				break;

			case 'usergroup_new':
				$shop->usergroupNew();
				break;

			case 'couponcodes':
				$shop->couponCodes($tpl_dir);
				break;

			case 'couponcodes_new':
				$shop->couponCodesNew();
				break;




//			case 'new_categ':
//				$shop->newCateg($tpl_dir);
//				break;

			case 'showorder':
				$shop->showOrder($tpl_dir, $_REQUEST['Id']);
				break;
				
			case 'set_user_group':
				$shop->set_user_group($_REQUEST['usergroup'], $_REQUEST['user']);
				break;

			case 'showorders':
				$shop->showOrders($tpl_dir);
				break;

			case 'mailpage':
				$shop->mailPage($tpl_dir, $_REQUEST['OrderId']);
				break;

//			case 'mark_failed':
//				$shop->markFailed($_REQUEST['Id']);
//				break;



//				case 'variants_categories2':
//					$shop->variantsCategories2($tpl_dir);
//				break;
//
//				case 'edit_variants_category2':
//					$shop->editVariantsCategory2($tpl_dir,$_REQUEST['Id']);
//				break;
//
//				case 'new_variants_category2':
//					$shop->newVariantsCategories2($tpl_dir);
//				break;
//
//				case 'delete_variants_category2':
//					$shop->deleteVariantsCategory2($_REQUEST['Id']);
//				break;




				case 'array_js':				
					$shop->array_js($tpl_dir, $_REQUEST['KatId'], $_REQUEST['product_id']);
				break;



				case 'mark_failed':
					$shop->markFailed(addslashes($_REQUEST['OrderId']), addslashes($_REQUEST['pr']));
				break;

			case 'parse':
				$shop->parse($tpl_dir);
			break;	
				
			case 'showmoney':
				$shop->showMoney($tpl_dir);
				break;

			case 'esd_downloads':
				$shop->esdDownloads($tpl_dir);
				break;

			case 'vatzones':
				$shop->vatZones($tpl_dir);
				break;

			case 'dataexport':
				$shop->dataExport($tpl_dir);
				break;

			case 'helppages' :
				$shop->helpPages($tpl_dir);
				break;

			case 'shopimport':
				$shop->shopImport($tpl_dir);
				break;

			case 'userimport':
				$shop->userImport($tpl_dir);
				break;

			case 'customerdiscounts':
				$shop->customerDiscounts($tpl_dir);
				break;

			case 'shop_downloads':
				$shop->shopDownloads($tpl_dir);
				break;

			case 'staffel_preise':
				$shop->staffelPreise($tpl_dir);
				break;

			case 'ximp':
				$shop->imp();
				break;

			case 'settingsyml':
				$shop->settingsYML($tpl_dir);
				break;
				
				case 'addcomment':
					$shop->addcomment($tpl_dir,$_REQUEST['numorder'],$_REQUEST['comment']);
				break;
				
				case 'addidentifikator':
					$shop->addidentifikator($tpl_dir,$_REQUEST['numorder'],$_REQUEST['comment']);
				break;
				
				case 'generate107':
					$orderid = (int)$_REQUEST['orderid'];
					$row = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_modul_shop_bestellungen WHERE Id = '".$orderid."'")->fetcharray();
					$RussianpostLabel107->display('',$tpl_dir,$row);
				break;
				
				case 'generatereceipt':
					$orderid = (int)$_REQUEST['orderid'];
					$row = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_modul_shop_bestellungen WHERE Id = '".$orderid."'")->fetcharray();
					$receipt->display2('',$tpl_dir,$row);
				break;	

				
				case 'get_log_payment':
					$shop->get_log_payment($tpl_dir,$_REQUEST['order']);
				break;	


				case 'dopshipper':
					$shop->dopshipper($tpl_dir, $_REQUEST['versandarten']);
				break;
				
				case 'delete_dopshipper':
					$shop->delete_dopshipper($_REQUEST['Id'], $_REQUEST['versandarten']);
				break;
				
				case 'zones':
					$shop->Zones($tpl_dir);
				break;

				case 'edit_reqest':
					$shop->edit_reqest($tpl_dir, $_REQUEST['request_number']);
				break;
				
				case 'read_request':
					$shop->read_request((int)$_REQUEST['id'], (int)$_REQUEST['value']);
				break;
				
				case 'delete_message':
					$shop->delete_message($tpl_dir, $_REQUEST['request_number'], $_REQUEST['messageId']);
				break;	
				
				
				case 'admin_reqest':
					$shop->admin_reqest($tpl_dir, $_REQUEST['orders']);
				break;
				
				case 'read_admin_request':
					$shop->read_admin_request((int)$_REQUEST['id'], (int)$_REQUEST['value']);
				break;
				
				case 'delete_admin_message':
					$shop->delete_admin_message($tpl_dir, $_REQUEST['orders'], $_REQUEST['messageId']);
				break;	

				
				case 'showOrder_schet':
					$shop->showOrder_schet($_REQUEST['orderid']);
				break;
				
/// new
				case 'showOrder_prod':
					$shop->showOrder_prod($tpl_dir,$_REQUEST['Id']);
				break;

				case 'showOrder_prod_new':
					$shop->showOrder_prod_new($tpl_dir,'0');
				break;
				
				case 'reset_sess':
					$_SESSION['order_new'] = '';
					$action = "&moduleaction=".$_REQUEST['act'];
					$id = (isset($_REQUEST['Id']) && $_REQUEST['Id'] != "") ? "&Id=".$_REQUEST['Id'] : '';
					header("Location:index.php?do=modules&action=modedit&mod=shop".$action."&cp=".SESSION."&pop=1".$id."&session=new&products=new");
				break;


				
				
		}
	}
}

?>